<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="app">
        <input type="button" value="修改" @click="changePerson">
    </div>
    
    <script src="./js/vue.js"></script>
    <script>
        let vm = new Vue({
            el:"#app",
            data:{
                person:{
                    name:"王一星",
                    sex:"男",
                    age:18,
                    wife:{
                        name:"琪琪",
                        sex:"女",
                        age:16
                    }
                }        
            },
            methods:{
                changePerson(){
                    // this.person = {
                    //     name:"王二小"
                    // }
                    // this.person.age  = 19;
                    // console.log("this.person",this.person);

                    this.person.wife.name="新的琪琪";

                }
            },
            watch:{
                // person:function(newVal,oldVal){
                //     console.log("person被改了",newVal);     
                // }
                person:{
                    deep:true,
                    handler:function(newVal,oldVal){
                        console.log("person被改了",newVal);     
                    },
                    immediate:true
                }
            }
        });


    </script>
</body>
</html>